<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<!--确认模态框-->
<div class="modal fade" data-backdrop="static" data-keyboard="false" id="modal-commit">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">图纸下发确认</h4>
            </div>
            <div class="modal-body" style="margin-bottom:40px;">
                <form id="editForm" class="form-horizontal">
                    <input type="hidden" name="proCode" id="proCode">
                    <div class="col-md-12">
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="query-status">确认状态</label>
                            <div class="col-sm-8">
                                <select id="dsnIssueStatus" class="form-control" name="dsnIssueStatus">
                                    <option value="0">未下发</option>
                                    <option value="1">已下发</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn-edit">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<section class="content-header">
    <h1>图纸下发确认</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="query-proCode">项目编号</label>
                                    <input id="query-proCode" type="text" name="proCode" class="form-control"
                                           placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label for="query-proName">项目名称</label>
                                    <input id="query-proName" type="text" name="proName" class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label for="query-demander">需方</label>
                                    <input id="query-demander" type="text" name="demander" class="form-control"
                                           placeholder="请输入需方">
                                </div>
                                <div class="form-group">
                                    <label for="query-address">地点</label>
                                    <input id="query-address" type="text" name="address" class="form-control"
                                           placeholder="请输入地点">
                                </div>
                                <div class="form-group">
                                    <label for="query-proNum">数量</label>
                                    <input id="query-proNum" type="text" name="proNum" class="form-control"
                                           placeholder="请输入数量">
                                </div>
                            </div>
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="query-status">下发状态</label>
                                    <select id="query-status" class="form-control" name="status">
                                        <option value="2" selected="selected">未下发</option>
                                        <option value="1">已下发</option>
                                        <option value="">全部</option>
                                    </select>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"
                                        onclick="js.table.search(table)">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    var table;

    /** 图纸下发确认 */
    function commit(row) {
        $("#proCode").val(row.proCode);
        $("#dsnIssueStatus").val(row.dsnIssueStatus).trigger("change");
        js.modal.open('modal-commit')
    }

    $(function () {

        /** 设计项目列表 */
        table = js.table.init({
            url: ctx + "designTask/dsnIssue/list",
            showExport: false,
            columns: [
                {
                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: "项目编号", field: 'proCode', width: '100'},
                {title: "项目名称", field: 'proName', width: '260'},
                {title: "需方", field: 'demander'},
                {title: "安装地点", field: 'address'},
                {title: "数量", field: 'proNum', width: '70'},
                {
                    title: "设计科室", field: 'deptName',
                    formatter: function (value, row) {
                        if (value != null) {
                            return value.split(',').join('<br>');
                        }
                    }, width: '150'
                },
                {title: "备注", field: 'comment', width: "150"},
                {
                    title: "设计图纸<br>下发状态", field: 'dsnIssueStatus',
                    formatter: function (value, row) {
                        if (value === 0) {
                            return '<span class="badge label-inverse">未下发</span>';
                        } else if (value === 1) {
                            return '<span class="badge label-success">已下发</span>';
                        }
                    }
                },
                {
                    title: "操作", width: 70,
                    formatter: function (value, row) {
                        let actions = [];
                        if (hasP('dsn:proIssue:edit')) {
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="commit(' + js.jsonStringify(row) + ')"> 编辑</a>');
                        }
                        return actions.join('');
                    }
                }
            ]
        });

        /** 图纸下发状态确认 */
        $("#btn-edit").click(function () {

            if ($('#dsnIssueStatus option:selected').val() == "") {
                js.modal.warning("请选择图纸下发状态");
                return;
            }

            js.post({
                url: ctx + "designTask/dsnIssue/commit",
                data: {proCode: $("#proCode").val(), dsnIssueStatus: $('#dsnIssueStatus option:selected').val()},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                        js.modal.hide("modal-commit");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        });

        js.modal.hideEvent("modal-commit", function () {
            js.reset("editForm");
        });

    });
</script>
</body>
</html>
